package com.yunxin.customui.service.createimpl;

import cn.hutool.core.map.CaseInsensitiveMap;
import com.yunxin.customui.bean.echart.ChartBean;
import com.yunxin.customui.bean.echart.ChartSqlConfig;
import com.yunxin.customui.service.CustomPageTemplate;
import com.yunxin.customui.mapper.ExecuteMapper;
import com.yunxin.customui.util.CustomSQLUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Component
public class CustomChartImpl extends CustomPageTemplate<List<CaseInsensitiveMap<String,Object>>, ChartSqlConfig, ChartBean,Map<String,Object>> {


    @Resource
    ExecuteMapper executeMapper;

    @Override
    protected List<CaseInsensitiveMap<String,Object>> getData(ChartSqlConfig config, Map<String,Object> paramMap) {
        //Sql查询获取数据
        String sql = CustomSQLUtil.buildSQL(config.getDataSql(), paramMap);
        return executeMapper.executeReadSql(sql);
    }

    @Override
    protected ChartBean build(List<CaseInsensitiveMap<String,Object>> stringListMap, ChartSqlConfig config) {
        //加载配置 & 数据结构转换
        ChartBean chartBean = new ChartBean(config);
        chartBean.build(config,stringListMap);

        return chartBean;
    }
}
